<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //字符串方法endsWith
        let str = '1.jpg'
        if(str.endsWith('.txt')){
            console.log('这是文本文件')
        }else if(str.endsWith('.jpg')){
            console.log('图片文件')
        }else{
            console.log('其他文件')
        }
    </script>
</body>
</html>